﻿using Microsoft.AspNetCore.Mvc;
using extensions.common;

namespace extensions.api.Controllers
{
    /// <summary>
    /// 通用扩展操作
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CommonController : ControllerBase
    {
        [HttpGet]
        public IActionResult To(string? str)
        {
            return Ok(str.To<int>());
        }

        [HttpGet]
        public IActionResult HasValue(string? str)
        {
            return Ok(str.Valid());
        }

        [HttpGet]
        public IActionResult Append(string? current, string? toAppend)
        {
            return Ok(current.Append(toAppend, true));
        }

        [HttpGet]
        public IActionResult Split(string? str)
        {
            return Ok(str.Split<int>());
        }

        [HttpGet]
        public IActionResult Utf8ToBase64(string? str)
        {
            return Ok(str.Utf8ToBase64());
        }
        
        [HttpGet]
        public IActionResult Base64ToUtf8(string? str)
        {
            return Ok(str.Base64ToUtf8());
        }
    }
}
